<?php
declare (strict_types = 1);
namespace app\common\helper\util;

class Timespan
{
    /**
     * 获取今日时间区间
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @return   [type]                         [description]
     */
    public static function getTodayTimespan()
    {
        $timespan = strtotime(date('Y-m-d'));
        return [$timespan, time()];
    }

    /**
     * 获取今日之前的时间区间
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-20
     * @return   [type]                         [description]
     */
    public static function getTodayBeforeTimespan()
    {
        $timespan = strtotime('today');
        
        return [0,$timespan];
    }
    /**
     * 昨日时间区间
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @return   [type]                         [description]
     */
    public static function getYesterdayTimespan()
    {
        $timespan = strtotime('yesterday');
        return [$timespan, $timespan + 86399];
    }
    /**
     * 前日时间区间
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @return   array
     */
    public static function getBeforeYesterdayTimespan()
    {
        $timespan = strtotime(date('Y-m-d', strtotime('-2 days')));
        return [$timespan, $timespan + 86399];
    }

    /**
     * 上周昨日时间区间
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @return   array
     */
    public static function getLastWeekYesterdayTimespan()
    {
        $timespan = strtotime('yesterday -1 week');
        return [$timespan, $timespan + 86399];
    }

    /**
     * 上上周昨日时间区间
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-16
     * @return   array
     */
    public static function getBeforeLastWeekYesterdayTimespan()
    {
        // 上上周昨日
        $timespan = strtotime('yesterday -2 week');
        return [$timespan, $timespan + 86399];
    }

    /**
     * 获取最近几天的时间段
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-07-17
     * @param    int|integer                    $days [description]
     * @return   [type]                               [description]
     */
    public static function getLateDaysTimespan(int $days = 1)
    {
        $timespan = strtotime('-' . $days . ' days');

        return [$timespan, time()];
    }

}
